package edu.isquen.core.department.action;

import edu.isquen.core.base.action.BaseAction;
import edu.isquen.core.department.model.Department;
import edu.isquen.core.department.service.DepartmentService;
import edu.isquen.util.factory.ServiceFactory;

public class DepartmentAction extends BaseAction<Department> {

	private static final long serialVersionUID = 7447034644536881723L;
	
	private String _superiorid;

	public DepartmentAction() throws Exception {
		super(ServiceFactory.createProcess(DepartmentService.class),
				new Department());
	}

	@Override
	public String doSave() {
		Department dept = (Department) this.getValObj();
		try {
			if (dept != null ) {
				Department superDept=dept.getSuperior();
				if(superDept==null || superDept.getId()==null || superDept.getId().equals("")){
					dept.setSuperior(null);
				}
				this.setValObj(dept);
				return super.doSave();
			}
		} catch (Exception e) {
			e.printStackTrace();
			return INPUT;
		}
		return SUCCESS;
	}
	
	public String get_superiorid() {
		return _superiorid;
	}

	public void set_superiorid(String superiorid) {
		_superiorid = superiorid;
	}
}
